#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1;
const int M = 1e9+7;
ll n;

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;      

    ll res = 0;
    for (ll i = 1; i <= n; i = 10*i + 1) 
        for (ll j = 1; i*j <= n; j *= 10)  
            res += min(j, n-i*j+1ll);
        

    cout << res << endl;
    return 0;
}